//
//  averageWidthCollectionViewController.m
//  CJUIKitDemo
//
//  Created by ciyouzen on 8/10/15.
//  Copyright (c) 2015 dvlproad. All rights reserved.
//

#import "TSMenuCollectionViewController.h"
#import <CQDemoKit/CJUIKitToastUtil.h>
#import <CQMenuListKit/CQMenuCollectionView.h>

@interface TSMenuCollectionViewController () {
    
}

@end

@implementation TSMenuCollectionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationItem.title = NSLocalizedString(@"水平滚动菜单列表视图", nil);
    
    
    NSMutableArray<CQMenuDataModel *> *dataModels = [[NSMutableArray alloc] init];
    for (NSInteger i = 0; i < 15; i++) {
        CQMenuDataModel *dataModel = [[CQMenuDataModel alloc] init];
        dataModel.name = [NSString stringWithFormat:@"%ldX透社", i];
        dataModel.imageUrl = @"https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=4012764803,2714809145&fm=26&gp=0.jpg";
        dataModel.badgeCount = i;
        [dataModels addObject:dataModel];
    }
    
    #pragma mark - 水平滚动的collectionView布局(index顺序能按照横向读完再读下一行)
    CQMenuCollectionView *horizontalCollectionView = [[CQMenuCollectionView alloc] initWithScrollDirection:UICollectionViewScrollDirectionHorizontal didTapShowingItemBlock:^(UICollectionView *collectionView, NSIndexPath *indexPath, CQMenuDataModel *dataModel) {
        NSString *message = [NSString stringWithFormat:@"点击了【%@】", dataModel.name];
        [CJUIKitToastUtil showMessage:message];
    }];
    horizontalCollectionView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:horizontalCollectionView];
    [horizontalCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view).mas_offset(120);
        make.left.mas_equalTo(self.view).mas_offset(15);
        make.centerX.mas_equalTo(self.view);
        make.height.mas_equalTo(301);
    }];
    horizontalCollectionView.dataModels = dataModels;
    [horizontalCollectionView reloadData];
    
    //*
    // 获取cell的高度(如果有需要的话)
    CGFloat collectionViewHeight = [horizontalCollectionView heightByScreenMarginLeft:15 screenMarginRight:15 maxRowCount:2];
    [horizontalCollectionView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(collectionViewHeight);
    }];
    //*/
    
    
    
    
    #pragma mark - 水平滚动的collectionView布局(index顺序能按照横向读完再读下一行)
    CQMenuCollectionView *verticalCollectionView = [[CQMenuCollectionView alloc] initWithScrollDirection:UICollectionViewScrollDirectionVertical didTapShowingItemBlock:^(UICollectionView *collectionView, NSIndexPath *indexPath, CQMenuDataModel *dataModel) {
        NSString *message = [NSString stringWithFormat:@"点击了【%@】", dataModel.name];
        [CJUIKitToastUtil showMessage:message];
    }];
    verticalCollectionView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:verticalCollectionView];
    [verticalCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(horizontalCollectionView.mas_bottom).mas_offset(40);
        make.left.mas_equalTo(self.view).mas_offset(15);
        make.centerX.mas_equalTo(self.view);
        make.height.mas_equalTo(301);
    }];
    verticalCollectionView.dataModels = dataModels;
    [verticalCollectionView reloadData];
}


@end
